<?php

declare (strict_types=1);

namespace app\model\auth;

use app\common\model\AuthRole;

class Role
{
    /**
     * 获取权限组列表
     *
     * @param array $childrenGroupIds 当前管理员所拥有权限的管理员
     *
     * @return array
     */
    public function getAuthGroupList(array $childrenGroupIds): array
    {
        $list = AuthRole::whereIn('id', $childrenGroupIds)
            ->field('id, pid, name')
            ->select();
        if ($list->isEmpty()) {
            return [];
        }
        return $list->toArray();
    }

    /**
     * 获取所有角色
     *
     * @param array $data 条件数据
     *
     * @return array
     */
    public function getAuthGroupAll(array $data): array
    {
        return AuthRole::whereIn('id', array_keys($data))->select()->toArray();
    }
}
